from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

# 启动 Edge 浏览器
driver = webdriver.Chrome()

# 打开页面
driver.get("file:///F:/TestProject/register.html")

# 等待页面加载完成
WebDriverWait(driver, 10).until(
    lambda d: d.execute_script("return document.readyState") == "complete"
)

# 等待 iframe 出现并切换到第一个 iframe
try:
    WebDriverWait(driver, 10).until(
        EC.frame_to_be_available_and_switch_to_it((By.NAME, "myframe1"))
    )
    print("切换到注册页面")
except TimeoutException:
    print("无法找到名为 'myframe1' 的 iframe")

# 切换回主窗口
driver.switch_to.default_content()

# 等待第二个 iframe 出现并切换到第二个 iframe
try:
    WebDriverWait(driver, 10).until(
        EC.frame_to_be_available_and_switch_to_it((By.NAME, "myframe2"))
    )
    print("切换到登录页面")
except TimeoutException:
    print("无法找到名为 'myframe2' 的 iframe")

# 关闭浏览器
driver.quit()